package net.zoneland.greenleaf.timer.service;


import org.apache.log4j.Logger;

import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.UUID;

import net.zoneland.greenleaf.timer.dao.Sys_schedulejobDao;
import net.zoneland.greenleaf.timer.entity.Sys_schedulejob;

import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * SYS_SCHEDULEJOB[定时任务信息表]表操作Serfice实现类

 * 类   名：Sys_schedulejobServiceImpl<br/>
 * 表   名：SYS_SCHEDULEJOBSERVICEIMPL<br/>
 * 注   释：<br/>
 * 作   者：GREENLEAF<br/>
 * 单   位：浙江兰德纵横网络技术有限公司<br/>
 * 日   期：2014-12-19 22:34:18
**/
@Service("sys_schedulejobService")
public class Sys_schedulejobServiceImpl implements Sys_schedulejobServiceI { 

	public static Logger logger = Logger.getLogger(Sys_schedulejobServiceImpl.class);

	/**
	 * 自动注入DAO对象
	**/
	@Autowired
	private Sys_schedulejobDao sys_schedulejobDao;

	/**
	 * 新增或者更新数据方法接口
	**/
	@Override
	public Sys_schedulejob addOrUpdate(Sys_schedulejob sys_schedulejob){
		try {
			if (sys_schedulejob == null) {
				logger.warn(Sys_schedulejob.class.getName() + "对象参数信息为Empty！");
				return null;
			}
			Map map = new HashMap();
			map.put("jobid", sys_schedulejob.getJobid());
			List list  = sys_schedulejobDao.getList(map);
			if(list!=null &&list.size()>0){
				//说明 数据已经存在,直接更新数据
				sys_schedulejobDao.edit(sys_schedulejob);
				return sys_schedulejob;
			}else{
				//说明 数据目前不存在
				sys_schedulejob.setJobid( UUID.randomUUID() + "" );
				sys_schedulejobDao.add(sys_schedulejob);
				return sys_schedulejob;
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	/**
	 * 新增数据方法实现
	**/
	@Override
	public boolean add(Sys_schedulejob sys_schedulejob){
		try {
			sys_schedulejobDao.add( sys_schedulejob );
			return true;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	/**
	 * 更新数据方法实现
	**/
	@Override
	public boolean update(Sys_schedulejob sys_schedulejob){
		try {
			sys_schedulejobDao.edit( sys_schedulejob );
			return true;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	/**
	 * 查询数据方法实现
	**/
	@Override
	public Sys_schedulejob get( Map map ) {
		try {
			return sys_schedulejobDao.get( map );
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	/**
	 * 查询数据方法实现（列表）
	**/
	@Override
	public List<Sys_schedulejob> getList(Map map){ 
		List<Sys_schedulejob> list = null;
		try {
			list = sys_schedulejobDao.getList( map );
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		return list;
	}
	
	/**
	 * 查询数据总数方法实现
	**/
	@Override
	public int getListCount(Map map) { 
		int count = 0;
		try {
			count = sys_schedulejobDao.getListCount( map );
		} catch (Exception e) {
				count = 0;
		}
		return count;
	}
	
	/**
	 * 数据删除方法实现
	**/
	@Override
	public boolean delete(Map map){ 
		boolean flag = false;
		try {
			sys_schedulejobDao.delete( map );
			flag = true;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		return flag;
	}
	
}
